import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'systemVedioM',
  state: {},
  effects: {
    //查询菜单下拉列表
    *queryMenuList({ payload, callback }, { call, put, select }) {
      const userMenuDataSelector = yield select((_) => {
        return _.userM.userMenuData;
      });
      if (userMenuDataSelector) {
        callback(userMenuDataSelector);
      } else {
        message.error('查询菜单下拉列表失败!');
      }
    },

    //查询视频列表
    *queryTableList({ payload, callback }, { call, put }) {
      const response = yield call(api.systemVedio.queryTableList, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg || '查询系统视频列表失败!');
      }
    },
    //删除视频
    *deleteVedio({ payload, callback }, { call, put }) {
      const response = yield call(api.systemVedio.deleteVedio, payload);
      const { type } = payload;
      if (response && response.code == 0) {
        message.success('删除成功');
        callback();
      } else {
        message.error(response?.msg || '系统视频删除失败!');
      }
    },
    //新增编辑视频
    *addVedio({ payload, callback }, { call, put }) {
      const response = yield call(api.systemVedio.addVedio, payload);
      if (response && response.code == 0) {
        message.success('保存成功');
        callback();
      } else {
        message.error(response?.msg || '提交失败!');
      }
    },

    // 查询当前页面视频列表
    *queryVeidoList({ payload, callback }, { call, put }) {
      const response = yield call(api.queryVeidoList, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        message.error('获取视频数据失败!');
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
